home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / advancec.arc / MAIN.C < prev    next >
Text File  |  1992-01-24  |  4KB  |  167 lines

  1. /*
  2.     main.c
  3.  
  4.     user interface demonstration file
  5. */
  6.  
  7. #include "usrif.h"
  8. #undef    NULL
  9. #include "stdio.h"
  10.  
  11. main(argc, argv)
  12. int     argc;
  13. char    *argv[];
  14. {
  15. event_t     *myevent;
  16. window_t    *mywindow;
  17. void        init_app();
  18.  
  19.     /* initialize segmentation system */
  20.     initialize();
  21.  
  22.     /* initialize event and window managers */
  23.     init_event();
  24.     init_window();
  25.  
  26.     /* initialize application */
  27.     init_app();
  28.  
  29.     /* enter event-driven user interface */
  30.     while(TRUE)
  31.         {
  32.         /* get an event */
  33.         myevent = get_next_event();
  34.  
  35.         /* What kind of event was it? */
  36.         switch( myevent->what )
  37.             {
  38.             case    NULL_EVENT  :
  39.                 /* use this event for
  40.                    pseudobackground processes */
  41.                 break;
  42.  
  43.             case    ABORT_EVENT :
  44.                 /* interrupt! */
  45.                 break;
  46.  
  47.             case    KEY_EVENT   :
  48.  
  49.                 /* In what window did the KEY_EVENT occur? */
  50.                 mywindow = what_window( &(myevent->where));
  51.  
  52.                 if( mywindow == NULL)
  53.                     {
  54.                     /* must have been a desktop event */
  55.                     desktop( myevent);
  56.                     }
  57.                 else if( mywindow == front_window())
  58.                     {
  59.                     /* call key function */
  60.                     if( mywindow->key_fn != NULL)
  61.                         (*(mywindow->key_fn))(myevent, mywindow);
  62.                     }
  63.                 else
  64.                     /* keypress in obscured window */
  65.                     pop_window( mywindow);
  66.  
  67.                break;
  68.  
  69.             case    DN_BUTTON_EVENT :  /* button down */
  70.  
  71.                 /* In what window did DN_BUTTON_EVENT occur? */
  72.                 mywindow = what_window( &(myevent->where));
  73.  
  74.                 if( mywindow == NULL)
  75.                     {
  76.                     /* must have been a desktop event */
  77.                     desktop( myevent);
  78.                     }
  79.  
  80.                 else if( mywindow == front_window())
  81.                     {
  82.                     if( in_title( &(myevent->where), mywindow))
  83.                         /* call window-control function */
  84.                         mod_window( myevent, mywindow);
  85.  
  86.                     else if( mywindow->button_fn != NULL)
  87.                         /* call button function */
  88.                         (*(mywindow->button_fn))(myevent, mywindow);
  89.                     }
  90.                 else
  91.                     /* button down in obscured window */
  92.                     pop_window( mywindow);
  93.  
  94.                 break;
  95.             }
  96.  
  97.         }   /* loop forever */
  98. }
  99.  
  100. /*
  101.     application test code
  102. */
  103.  
  104. #define WINDOWS 4
  105. seg_t    *door, *window, *house;
  106. window_t *them[WINDOWS];
  107.  
  108. void    init_app()
  109. {
  110. window_t  *new_window();
  111. seg_t     *cl_seg();
  112.  
  113. /*
  114.     initialize application variables, windows, menu functions, etc.
  115. */
  116.  
  117.         cr_seg("window");
  118.         add_attr(RESET);
  119.         add_attr(BLACK);
  120.         rect(10,10,60,80);
  121.         rect(10,00,60,90);
  122.         window = cl_seg();
  123.  
  124.         cr_seg("door");
  125.         add_attr(RESET);
  126.         add_attr(BLACK);
  127.         rect(10,0,100,170);
  128.         door = cl_seg();
  129.  
  130.         cr_seg("house");
  131.  
  132.         add_attr(RESET);
  133.         add_attr(BLACK);
  134.  
  135.         rect(100,200,600,500);
  136.         begin_line();
  137.             con_point(50,480);
  138.             con_point(350,600);
  139.             con_point(650,480);
  140.         add_line(end_line());
  141.  
  142.         ref("window",150,300,NULL);
  143.         ref("window",250,300,NULL);
  144.         ref("window",350,300,NULL);
  145.  
  146.         ref("door",450,200,NULL);
  147.  
  148.         text("House", 0, 100, LEFT , BOTTOM);
  149.  
  150.     house = cl_seg();
  151.  
  152. /*
  153.     display house segment in four different windows
  154. */
  155.  
  156.     them[0] = new_window("Window 0", house, new_rect());
  157.     them[1] = new_window("Window 1", house,
  158.          inst_rect(150, 50,300,600));
  159.     them[2] = new_window("Window 2", house, new_rect());
  160.     them[3] = new_window("Window 3 is the last", house,
  161.          inst_rect(100,100,600,300));
  162.  
  163. /*
  164.     return to event loop
  165. */
  166. }
  167.